package com.shujia.scala

import scala.collection.mutable.ListBuffer

object Demo15ListBuffer {
  def main(args: Array[String]): Unit = {

    /**
      * 可变集合
      *
      */

    val listBuffer: ListBuffer[Int] = new ListBuffer[Int]

    //增加元素
    listBuffer.+=(1)

    listBuffer += 2

    println(listBuffer)


    //增加多个元素
    listBuffer ++= List(1, 2, 3, 5)

    println(listBuffer)

    //删除一个䛾
    listBuffer -= 2

    println(listBuffer)

    //通过下表获取元素
    println(listBuffer(2))

    //通过下标更新元素
    listBuffer.update(4, 10)

    println(listBuffer)

    //通过下标更新元素
    listBuffer(4) = 100

    println(listBuffer)


    //将listbuffer转换成list
    val list: List[Int] = listBuffer.toList

    println(list)

  }

}
